package com.example.amoxicilin.null_test.tools;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class CodeTools {
	
	//将字符串中的中文转为UTF-8编码，英文不变
	public static String UTF8Encoder(String content) throws UnsupportedEncodingException {
		String newString = "";
		int length = content.length();
		
		for(int i=0;i<length;i++) {
			
			if(checkChinese(content.charAt(i))) {
				String temp = "" + content.charAt(i);
				newString += URLEncoder.encode(temp, "UTF-8");
			} else {
				newString += content.charAt(i);
			}
			
		}
		
		return newString;
	}
	
	//判断是否中文字
	public static boolean checkChinese(char word) {
	   if ((word >= 0x4e00)&&(word<=0x9fbb)) {
		   return true;
	   } else {
		   return false;
	   }
	}
	
	

}
